<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    body {
      min-height: 250vh;
      background: #333;
    }
  </style>
</head>

<body>

</body>
<script>
  window.onscroll = timer(() => {
    console.log(document.documentElement.scrollTop);
  }, 500)
  function timer(fun, wait) {
    let time = null
    return function () {
      if (time) {
        clearTimeout(time)
      }
      time = setTimeout(fun, wait)
    }

  }
</script>

</html>